package com.example.day15;

import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.Log;

public class MyIntentService extends IntentService {

    public MyIntentService() {
        super("myasdas");
    }
    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */


    public MyIntentService(String name) {
        super(name);
    }

//    @Override
//    public void onStart(@Nullable Intent intent, int startId) {
//        super.onStart(intent, 4);
//    }

    @Override
    public void onCreate() {
        Log.e("MIntentService--", "onCreate");
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e(startId+"MIntentService--", "onStartCommand");
//        Intent intent1= getI
        return super.onStartCommand(intent, flags, startId);
    }
    @Override
    protected void onHandleIntent(Intent intent) {
        Log.e("MIntentService--", Thread.currentThread().getName() + "--" + intent.getStringExtra("info") );
        for(int i = 0; i < 10; i++){ //耗时操作
            Log.e("onHandleIntent--",  i + "--" + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    @Override
    public void onDestroy() {
        Log.e("MIntentService--", "onDestroy");
        super.onDestroy();
    }
}
